package com.finstone.data.spider.eshop.service.impl;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Spider;

import com.finstone.data.spider.eshop.downloader.ImageDownloader;
import com.finstone.data.spider.eshop.pipeline.EShopGoodsDetailImagePipline;
import com.finstone.data.spider.eshop.processor.EShopGoodsDetailImageProcessor;
import com.finstone.data.spider.eshop.service.AbstractSpiderService;

@Component
public class EShopGoodsDetailImageService extends AbstractSpiderService<Map<String, String>> {

	@Autowired
	private EShopGoodsDetailImageProcessor eShopGoodsDetailImageProcessor;

	@Autowired
	private EShopGoodsDetailImagePipline eShopGoodsDetailImagePipline;

	@Override
	@PostConstruct
	public void init() {
		spider = Spider.create(eShopGoodsDetailImageProcessor).setDownloader(new ImageDownloader()).addPipeline(eShopGoodsDetailImagePipline);
	}

	@Override
	protected void doPutTask(Map<String, String> imageMap) {
		String url = imageMap.get("url");
		String id = imageMap.get("id");
		String dir_id = imageMap.get("dir_id");
		String real_id = imageMap.get("real_id");
		Request request = new Request(url);
		request.putExtra("id", id);
		request.putExtra("dir_id", dir_id);
		request.putExtra("real_id",real_id);
		spider.addRequest(request);
	}
}
